﻿using System;
using System.Data;
using System.Data.Common;
using System.Globalization;
using Gammar.Price.ObjectModel;
using Longbow.Data;

namespace Gammar.Price.DataAccess
{
    /// <summary>
    /// 
    /// </summary>
    public partial class Category : ReaderCommand<CategoryEntity>
    {   
        /// <summary>
        /// 
        /// </summary>            
        protected override CommandType CommandType
        {
            get { return CommandType.Text; }
        }

        private string _criteria;
        
        /// <summary>
        /// 
        /// </summary>
        public string Criteria
        {
            get { return _criteria; }
            set { _criteria = value; }
        }
        
        /// <summary>
        /// 
        /// </summary>
        protected override string CommandText
        {
            get
            {
                string sql = "select * from Category";
                if (!string.IsNullOrEmpty(Criteria))
                    sql = string.Format(CultureInfo.InvariantCulture, "{0} {1}", sql, Criteria);
                return sql;
            }        
        }

        /// <summary>
        /// 
        /// </summary>            
        protected override void AddParameters(DbParameterCollection parameters, DBAccess db)
        {

        }

        /// <summary>
        /// 
        /// </summary>            
        protected override CategoryEntity ParseRow(DbDataReader reader)
        {
            CategoryEntity obj = new CategoryEntity();
            obj.Cat_id = (Guid?)DBAccess.ToObjectValue(reader["Cat_id"]);
            obj.CClass_ID = (Guid?)DBAccess.ToObjectValue(reader["CClass_ID"]);
            obj.Cat_Name = (string)DBAccess.ToObjectValue(reader["Cat_Name"]);
            obj.Cat_TbName = (string)DBAccess.ToObjectValue(reader["Cat_TbName"]);
            return obj;
        }
    }
}